﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace OnlineMealOrdering.Common
{
	public class MessageShow
	{
        public static string ShowException(string message)
        {
            return ShowException("", message);
        }

        public static string ShowException(Exception ex)
        {
            string message = message = GetExceptionMsg(ex);
            string title = string.Empty;
            if (ex is BusinessException)
            {
                title = "业务错误";
            }
            else if (ex is EPSystemException)
            {
                title = "系统错误";
            }


            return ShowException(title, message);
        }

        private static string ShowException(string title, string message)
        {
            string str = string.Format("<script type=\"text/javascript\" lang=\"javascript\">showMessage('fault','{0}','{1}');</script>", title, message);
            str = str.Replace("\r\n", "");
            return str;
        }

        private static string GetExceptionMsg(Exception ex)
        {
            Exception trueException = ex;
            while (trueException.InnerException != null)
                trueException = trueException.InnerException;

            return trueException.Message;
        }
	}
}